package String;

public class StringBuilderDemo {
    public static void main(String[] args) {
        StringBuilder builder = new StringBuilder("好好学习java" );
        builder.append(",为了找个好工作");//添加内容在末尾
          System.out.println(builder);//可以直接输出
        builder.replace(9,16,"就是为了改变世界");//替换的部分内容含头不含尾
        System.out.println(builder);
        builder.delete(0,8);  //删除下标为0到7的
        System.out.println(builder);
        builder.insert(0,"活着");//在下标为0的位置插入活着
        System.out.println(builder);//活着就是为了改变世界
        builder.reverse();//反转builder内容
        System.out.println(builder);

       /* StringBuilder sb = new StringBuilder("hello");//初始为5+16
        System.out.println(sb);
        StringBuilder sb1 = new StringBuilder();//初始为16
        int len =sb1.length();
        System.out.println(len);

        //String 和StringBuilder相互转换
        String str ="abc";
        StringBuilder  builder3 = new StringBuilder(str);   ///abc串 基于String对象构造StringBuilder对象
        String str2 = builder3.toString ();//将builder3转换为String
*/


   



    }
}
